import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';

@Entity('miniprogram_sessions')
export class MiniProgramSession {
  @ApiProperty({ description: '会话ID' })
  @PrimaryGeneratedColumn()
  id: number;

  @ApiProperty({ description: '用户ID' })
  @Column()
  userId: number;

  @ApiProperty({ description: '微信openid' })
  @Column({ length: 100 })
  openid: string;

  @ApiProperty({ description: '微信unionid' })
  @Column({ length: 100, nullable: true })
  unionid: string;

  @ApiProperty({ description: '会话密钥' })
  @Column({ length: 100 })
  sessionKey: string;

  @ApiProperty({ description: '访问令牌' })
  @Column({ length: 500 })
  accessToken: string;

  @ApiProperty({ description: '令牌过期时间' })
  @Column()
  expiresAt: Date;

  @ApiProperty({ description: '状态：0-无效，1-有效' })
  @Column({ default: 1 })
  status: number;

  @ApiProperty({ description: '创建时间' })
  @CreateDateColumn()
  createdAt: Date;

  @ApiProperty({ description: '更新时间' })
  @UpdateDateColumn()
  updatedAt: Date;
}
